package com.example.app2;

import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {
    private EditText edtNo;
    private Button btnSearch;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        edtNo = findViewById(R.id.edt_no);
        btnSearch = findViewById(R.id.btn_search);

        btnSearch.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MyDataBaseHelper helper = new MyDataBaseHelper(MainActivity.this);
                SQLiteDatabase db = helper.getReadableDatabase();
                String key = edtNo.getText().toString();
                String where = "no = "+key;
                Cursor cursor = db.query("student",null,where,null,null,null,null);
                cursor.moveToFirst();
                String name = cursor.getString(2);
                String birth = cursor.getString(3);
                String phone  = cursor.getString(4);

                Intent intent = new Intent(MainActivity.this,StudentActivity.class);
                intent.putExtra("NO", key);
                intent.putExtra("NAME", name);
                intent.putExtra("BIRTH", birth);
                intent.putExtra("PHONE", phone);
                startActivity(intent);
            }
        });

    }
}
